// This is a javascript file

function checkRequiredFields(){
	if(!document.getElementById || !document.createTextNode){return;}
	
	var fnameField=document.getElementById('first_name');
	var lnameField=document.getElementById('last_name');
	var emailField=document.getElementById('email_1');
	var checkEmailField=document.getElementById('email_2');
        var pass01Field=document.getElementById('pass01');
        var pass02Field=document.getElementById('pass02');
	
	if(!fnameField || !lnameField || !emailField || !checkEmailField || !pass01Field || !pass02Field ){return;}
	
	var fnameErrorContainer=fnameField.parentNode.getElementsByTagName('span')[0];
	var lnameErrorContainer=fnameField.parentNode.getElementsByTagName('span')[1];
	var emailErrorContainer=fnameField.parentNode.getElementsByTagName('span')[2];
	var checkEmailErrorContainer=fnameField.parentNode.getElementsByTagName('span')[3];
        var pass01ErrorContainer=fnameField.parentNode.getElementsByTagName('span')[4];
        var pass02ErrorContainer=fnameField.parentNode.getElementsByTagName('span')[5];
	
	if(!fnameErrorContainer){return;}
	if(!lnameErrorContainer){return;}
	if(!emailErrorContainer){return;}
	if(!checkEmailErrorContainer){return;}
        if(!pass01ErrorContainer){return;}
        if(!pass02ErrorContainer){return;}
	
	var checkEmailPattern = /^[\w]+(\.[\w]+)*@([\w]+\.)+[a-z]{2,7}$/i;
	//var checkEmailPattern= new RegExp("");
	
	var errorFlag = 0;
	var fnameErrorMessage='';
	var lnameErrorMessage='';
	var emailErrorMessage='';
	var checkEmailErrorMessage='';
        var pass01ErrorMessage='';
        var pass02ErrorMessage='';
	
	fnameErrorContainer.firstChild.nodeValue=' ';
	lnameErrorContainer.firstChild.nodeValue=' ';
	emailErrorContainer.firstChild.nodeValue=' ';
	checkEmailErrorContainer.firstChild.nodeValue=' ';
        pass01ErrorContainer.firstChild.nodeValue=' ';
        pass02ErrorContainer.firstChild.nodeValue=' ';
	
	var fnameValue=fnameField.value;
	var lnameValue=lnameField.value;
	var emailValue=emailField.value;
	var checkEmailValue=checkEmailField.value;
        var pass01Value=pass01Field.value;
        var pass02Value=pass02Field.value;
	
	if(fnameValue==''){
		fnameErrorMessage='Please enter your first name.';
		errorFlag = 1;
		}
	if(lnameValue==''){
		lnameErrorMessage='Please enter your last name.';
		errorFlag = 1; 
		}
	if(emailValue==''){
		emailErrorMessage='Please enter your email address.';
		errorFlag = 1;
		}else if(!checkEmailPattern.test(emailValue)){
			emailErrorMessage='Please enter a valid email address';
			errorFlag = 1;
			}else if(checkEmailValue==''){
				checkEmailErrorMessage='Please enter your email address again.';
				errorFlag = 1;
				}else if(emailValue!=checkEmailValue){
					checkEmailErrorMessage='Email mis-match, please re-enter your email address.';
					errorFlag = 1;
					} 
        if(pass01Value==''){
            pass01ErrorMessage='Please create a password.';
            errorFlag = 1;
            } else if(pass01Value!=pass02Value){
                pass02ErrorMessage='Password verification mismatch.  Please re-type password.';
                errorFlag = 1;
                }
	if(fnameErrorMessage!=''){
		fnameErrorContainer.firstChild.nodeValue=fnameErrorMessage;
		}
	if(lnameErrorMessage!=''){
		lnameErrorContainer.firstChild.nodeValue=lnameErrorMessage;
		}
	if(emailErrorMessage!=''){
		emailErrorContainer.firstChild.nodeValue=emailErrorMessage;
		}
	if(checkEmailErrorMessage!=''){
		checkEmailErrorContainer.firstChild.nodeValue=checkEmailErrorMessage;
		}
        if(pass01ErrorMessage!=''){
            pass01ErrorContainer.firstChild.nodeValue=pass01ErrorMessage;
            }
        if(pass02ErrorMessage!=''){
            pass02ErrorContainer.firstChild.nodeValue=pass02ErrorMessage;
            }
	
	if(errorFlag!=0){
		return false;
		}else{return true;} 
}
